﻿using Pb;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DDZCreatRoom : MonoBehaviour {

    public List<GameObject> ChooseStatus;
    public List<GameObject> ChooseBtn;
    public GameObject CreatRoomBtn;
    public GameObject CloseBtn;
    private void Awake()
    {
        for (int i = 0; i < ChooseBtn.Count; i++)
        {
            UIEventListener.Get(ChooseBtn[i]).onClick = ButtonClick;
        }

        UIEventListener.Get(CreatRoomBtn).onClick = ButtonClick;
        UIEventListener.Get(CloseBtn).onClick = ButtonClick;
    }
    void ButtonClick(GameObject button)
    {
        if (button.name == "1")
        {
            ChooseStatus[0].SetActive(true);
            ChooseStatus[1].SetActive(false);
            ChooseStatus[2].SetActive(false);

        }
        else if (button.name == "2")
        {
            ChooseStatus[0].SetActive(false);
            ChooseStatus[1].SetActive(true);
            ChooseStatus[2].SetActive(false);

        }
        else if (button.name == "3")
        {
            ChooseStatus[0].SetActive(false);
            ChooseStatus[1].SetActive(false);
            ChooseStatus[2].SetActive(true);
        }
        else if (button.name == "CreatRoomBtn")
        {
            SendCreatRoom();

        }
        else if (button.name == "CloseBtn")
        {
            Destroy(gameObject);
        }
    }
    void SendCreatRoom()
    {
        int TotalRound = 0;

        for (int i = 0; i < ChooseStatus.Count; i++)
        {
            if (ChooseStatus[i].activeSelf)
            {

                Debug.Log("roomTypeId:" + i);
                if (i == 0)
                {
                    TotalRound = 4;
                }
                else if (i == 1)
                {
                    TotalRound = 8;
                }
                else if (i == 2)
                {
                    TotalRound = 16;
                }
            }

        }

        DdzOpenRoomRequest MR = new Pb.DdzOpenRoomRequest { TotalRound = TotalRound };
        SocketManager socketManager = SocketManager.Instance;
        socketManager.SendProtobuf1(MR, MsgId.DdzOpenRoomRequest);

    }
}
